//
//  ReportDetailViewController.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/6/2.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "ReportDetailViewController.h"
#import "ReportTopCell.h"
#import "ReportImgCell.h"
#import "ReportTextCell.h"
#import <UITableView_FDTemplateLayoutCell/UITableView+FDTemplateLayoutCell.h>
@interface ReportDetailViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
}
@property(nonatomic,weak)IBOutlet UITableView *mainTableView;
@property(nonatomic,weak)IBOutlet UIButton *fenxiBtn;
@end

@implementation ReportDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"已有报告";
    self.fenxiBtn.layer.cornerRadius = 20;
    [self configTableView];
}
-(void)configTableView{
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    self.mainTableView.tableFooterView = [UIView new];
    [self.mainTableView registerNib:[UINib nibWithNibName:@"ReportTopCell" bundle:nil] forCellReuseIdentifier:@"ReportTopCell"];
    [self.mainTableView registerNib:[UINib nibWithNibName:@"ReportImgCell" bundle:nil] forCellReuseIdentifier:@"ReportImgCell"];
    [self.mainTableView registerNib:[UINib nibWithNibName:@"ReportTextCell" bundle:nil] forCellReuseIdentifier:@"ReportTextCell"];
    self.mainTableView.showsVerticalScrollIndicator = NO;
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.mainTableView.backgroundColor = [UIColor clearColor];
}
#pragma mark - UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            return 76;
        }
            break;
        case 1:
        {
            return 155;
        }
            break;
        case 2:
        {
            return [tableView fd_heightForCellWithIdentifier:@"ReportTextCell" configuration:^(id cell) {
                [self configCell:cell indexPath:indexPath];
            }];
        }
            break;
        default:
            return 0;
            break;
    }
}
-(void)configCell:(ReportTextCell*)cell indexPath:(NSIndexPath*)indexPath{
    cell.reportText.text = @"最早在不列颠建立国家的，应该是前2000年代广泛分布在欧洲的凯尔特文明。关于凯尔特人的知识主要是从罗马人的历史记载中获得。他们信奉自然宗教，各部族之间只有松散的联系，没有形成统一的政治实体，自然也没有王朝。尽管如此原始他们的力量不容小觑，在公元前390年，凯尔特人洗劫了罗马城（显然，并不是居住在不列颠的那个部族）。\n凯尔特人之后，罗马人占据了不列颠的中南部凯撒曾经在不列颠修筑据点，击败凯尔特人，但真正在这里建立有效统治的，是克劳狄一世（奥古斯都的孙辈，李维的学生）。";
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            ReportTopCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReportTopCell" forIndexPath:indexPath];
            cell.backgroundColor = [UIColor clearColor];
            cell.contentView.backgroundColor = [UIColor clearColor];
            [cell.bgView setImage:[[UIImage imageNamed:@"topBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"topBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"topBg"].size.height/2]];
            return cell;
        }
            break;
        case 1:
        {
            ReportImgCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReportImgCell" forIndexPath:indexPath];
            cell.backgroundColor = [UIColor clearColor];
            cell.contentView.backgroundColor = [UIColor clearColor];
            [cell.bgView setImage:[[UIImage imageNamed:@"middleBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"middleBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"middleBg"].size.height/2]];
            return cell;
        }
            break;
        case 2:
        {
            ReportTextCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReportTextCell" forIndexPath:indexPath];
            cell.backgroundColor = [UIColor clearColor];
            cell.contentView.backgroundColor = [UIColor clearColor];
            [cell.bgView setImage:[[UIImage imageNamed:@"bottomBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"bottomBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"bottomBg"].size.height/2]];
            [self configCell:cell indexPath:indexPath];
            return cell;
        }
            break;
        default:
            return [UITableViewCell new];
            break;
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
